package com.hd.tiyu.yuejian.Fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hd.tiyu.yuejian.Activity.FaTieListActivity;
import com.hd.tiyu.yuejian.Activity.GeRenSettingActivity;
import com.hd.tiyu.yuejian.Activity.GuanZhuActivity;
import com.hd.tiyu.yuejian.Activity.PayActivity;
import com.hd.tiyu.yuejian.Activity.YueJianIntroActivity;
import com.hd.tiyu.yuejian.JavaBean.User;
import com.hd.tiyu.yuejian.Model.ListsModel;
import com.hd.tiyu.yuejian.R;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/9/14.
 */

public class WoFragment extends Fragment {
    private View view;
    private Context mContext;
    private TextView user_name,xiaoxiliang,guanzhuliang,fatieliang;
    private LinearLayout click_img0,click_img1,click_img2,click_img3,click_img4,click_img5,click_img6,click_img7;
    private SharedPreferences sp;
    private ImageView user_img;
    private String userId;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.wotab,container,false);
        initViews();
        initEvents();
        initDatas();
        return view;
    }

    private void initViews() {
        user_name=view.findViewById(R.id.uname);
        xiaoxiliang=view.findViewById(R.id.tex_xiaoxiliang);
        guanzhuliang=view.findViewById(R.id.tex_guanzhuliang);
        fatieliang=view.findViewById(R.id.tex_fatieliang);

        user_img=view.findViewById(R.id.uimg);
        click_img0=view.findViewById(R.id.click1);
        click_img1=view.findViewById(R.id.click2);
        click_img2=view.findViewById(R.id.click3);
        click_img3=view.findViewById(R.id.click4);
        click_img4=view.findViewById(R.id.click5);
        click_img5=view.findViewById(R.id.click6);
        click_img6=view.findViewById(R.id.click7);
        click_img7=view.findViewById(R.id.click8);

        sp=getActivity().getSharedPreferences("loginUser",Context.MODE_PRIVATE);
        userId=sp.getString("user_id","");
    }


    private void initEvents() {
        click_img6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(), YueJianIntroActivity.class);
                startActivity(intent);

            }
        });

        click_img7.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(), GeRenSettingActivity.class);
                startActivity(intent);

            }
        });

        click_img3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(), GuanZhuActivity.class);
                intent.putExtra("User_Id",userId);
                getActivity().startActivity(intent);
            }
        });

        click_img0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getContext(), PayActivity.class);
                getContext().startActivity(intent);
            }
        });

        click_img4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(), FaTieListActivity.class);
                intent.putExtra("User_Id",userId);
                getActivity().startActivity(intent);
            }
        });

    }


    private void initDatas() {
        ListsModel listsModel=new ListsModel();
        Call<User> call=listsModel.Userinfo(userId);
        call.enqueue(new Callback<User>() {
            @Override
            public void onResponse(Call<User> call, Response<User> response) {
                User data=response.body();
                user_name.setText(data.getUser_name());
                xiaoxiliang.setText("消息  "+data.getMessagenum());
                guanzhuliang.setText("关注  "+data.getFocusnum());
                fatieliang.setText("发帖  "+data.getShaitunum());
                //// Picasso.with(mContext).load("http://172.24.10.175/workout/Uploads/"+data.getPhoto()).resize(115,115).centerCrop().into(user_img);

            }

            @Override
            public void onFailure(Call<User> call, Throwable t) {

            }
        });
    }

}
